package arch.util;

import org.springframework.context.ApplicationContext;

/**
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public final class BeanRepository {
	private static ApplicationContext ctx = null;
	
	public static void setApplicationContext(ApplicationContext applicationContext) {
		ctx = applicationContext;
	}
	public static ApplicationContext getApplicationContext() {
		return ctx;
	}
	public static Object getBean(String id) {
		if(ctx == null) {
			return null;
		}
		return ctx.getBean(id);
	}
	
	@SuppressWarnings("unchecked")
	public static <T>T getBean(String id,Class<T> clazz) {
		if(ctx == null) {
			return null;
		}
		return (T)ctx.getBean(id);
	}
}
